package cn.udrm.elasticsearch.fileread;

import cpcns.office.fulltext.FilterFactory;
import cpcns.office.fulltext.ITextFilter;
import cpcns.office.fulltext.filter.AbstractFilter;

import java.io.File;

/**
 * 读取ofd文件内容
 * @author xurongbei
 */
public class OFDReadContent {

    public static String getOfdContent(File file) throws Exception {
        StringBuffer stringBuffer=new StringBuffer();
        AbstractFilter filter = FilterFactory.getInstance().getFilter("ofd");
        ITextFilter textFilter = filter.loadFile(file.getPath());
        int count = textFilter.getComponentCount();
        for(int i=0;i<count;i++){
            stringBuffer.append(textFilter.getComponentTextAt(i));
        }
        textFilter.close();
        return stringBuffer.toString();
    }
}
